package com.paipai.aop;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import org.aopalliance.intercept.Joinpoint;
import org.springframework.stereotype.Component;

import com.google.common.util.concurrent.RateLimiter;

@Component
//@Aspect
public class LimitAop {
	
	/*//方法名 -> 限流次数 
	private Map<String,RateLimiter> map = new HashMap<String,RateLimiter>() ;
	
	@Pointcut("execution(* com.moon.service.*.*(..))")
	public void point() {
		
	}
	
	@Around("Pointcut()")
	public Object around(ProceedingJoinPoint p) {
		String string = p.getTarget().toString();
		String name = p.getSignature().getName();
		
		Method met= p.getTarget().getClass().getDeclaredMethod("");
		
		Limit limit = met.getAnnotation(Limit.class);
		num=limit.value();
		//判断
		String fullName="";
		if(!map.containsKey(fullName)) {
			RateLimiter r = RateLimiter.create(num);
			map.put(fullName,r);
			return p.proceed();
		}else {
			RateLimiter r = map.get(fullName);
			if(r.tryAcquire()) {
				return p.proceed();
			}else {
				throws new 
			}
			
		}
		System.out.println("curr="+p.gettarget);
		return p.proceed();
	}*/

}
